package com.talkweb.securitycamera.data.hadoopFile;

import com.talkweb.dataprocesslib.ResourceTable;
import com.talkweb.securitycamera.common.base.utils.ResourceHelper;
import com.talkweb.securitycamera.common.constans.FileType;
import com.talkweb.securitycamera.common.interfaces.dataprocess.FileCallback;
import com.talkweb.securitycamera.utils.TimeUtils;
import ohos.app.Context;
import ohos.app.dispatcher.task.TaskPriority;
import ohos.media.image.Image;
import ohos.media.image.common.ImageFormat;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

/**
 * 查询与存储图片文件的类
 * class to query image files and save image files
 *
 * @author : frank
 * @date : 2021/2/2 10:03
 */
public class SimpleImageProcessor extends BaseMediaProcessor<File> {

    private Context mContext;

    private FileCallback fileCallback;

    private SimpleImageMemoryPolicy imageMemoryPolicy;

    public SimpleImageProcessor(Context context, FileCallback fileCallback) {
        mContext = context;
        this.fileCallback = fileCallback;
        imageMemoryPolicy = new SimpleImageMemoryPolicy();
    }

    public SimpleImageProcessor(Context context) {
        mContext = context;
    }


    @Override
    public Context getContext() {
        return mContext;
    }


    @Override
    public void addFile(File source, FileType type) {
        super.addFile(source, type);
        //TODO 插入数据库
    }

    @Override
    public File createSourceFile(FileType fileType) {
        checkMemory(imageMemoryPolicy, mContext);
        String suffix = ResourceHelper.getString(mContext, ResourceTable.String_iamge_suffix);
        File mediaDirectory = MediaDirectoryProvider.provideMediaDirectory(mContext, fileType);
        String hadoopFilePath = mediaDirectory.getAbsolutePath() + File.separator + TimeUtils.getTimeYYYYMMddHHmmss(System.currentTimeMillis()) + suffix;
        return new File(hadoopFilePath);
    }
}
